//
// Created by suzhen on 17-3-9.
//

#ifndef ORIONV2_COROUTINECORE_H
#define ORIONV2_COROUTINECORE_H


#include "Orion.h"
#include "BasicEventGenerator.h"

ORION_V2_NAMESPACE_BEGIN
        
        namespace Coroutine {
            
            
            class CoroutineCore {
            
            
            public:
                ~CoroutineCore();
                
                CoroutineCore(std::size_t coreIdx, bool autoStart = NO);
                
                void execute();
                
                void shutdown();
                
                void notify();
                
                void awakeFibers(BasicEventGenerator &);
                
                static void bindCpuFnAndApplyAlgo(std::size_t idx);
            
            public:
                CoroutineCore(const CoroutineCore &) = delete;
                
                CoroutineCore &operator=(const CoroutineCore &) = delete;
                
                CoroutineCore(CoroutineCore &&o)
                        : coreIdx_(o.coreIdx_),
                          gen_(o.gen_) {
                    o.gen_ = nullptr;
                }
                
                CoroutineCore &operator=(CoroutineCore &&o) {
                    if (this == &o) {
                        return *this;
                    }
                    coreIdx_ = o.coreIdx_;
                    gen_ = o.gen_;
                    o.gen_ = nullptr;
                    return *this;
                }
            
            private:
                std::size_t coreIdx_;
                BasicEventGenerator *gen_;
            };
            
            
        }
ORION_V2_NAMESPACE_END

#endif //ORIONV2_COROUTINECORE_H

